﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using MINERP.COM;

namespace MINERP.DAL.Statistics
{
    public class WasteDal:DALBase
    {
        /// <summary>
        /// 取得所有打印机
        /// </summary>
        /// <returns></returns>
        public ObjectQuery<printer>  GetAllPriner()
        {
            return DataEntites.printer;
        }
        /// <summary>
        /// 取得所有纸型
        /// </summary>
        /// <returns></returns>
        public ObjectQuery<paperFace> GetAllPaperFace()
        {
            return DataEntites.paperFace;
        }

        public ObjectQuery<paperType> GetAllPaperType()
        {
            return DataEntites.paperType;
        }
        public paperType GetPaperType(int paperTypeId)
        {
            return DataEntites.paperType.Where(p => p.PaperTypeID == paperTypeId).FirstOrDefault();
        }
        public paperFace GetPaperFace(int paperFaceId)
        {
            return DataEntites.paperFace.Where(p => p.PaperFaceID == paperFaceId).FirstOrDefault();
        }

        public List<Board> GetBoard(int printId,int inPaperTypeId,int inPaperFace, DateTime inStarTime,DateTime inEndTime)
        {
            if (printId == 0)
            {
                if (GetPaperType(inPaperTypeId).Name.Equals("任意"))
                {
                    if (GetPaperFace(inPaperFace).Name.Equals("任意"))
                    {
                        return DataEntites.Board.Where(p => p.lastPrintTime <= inEndTime && p.lastPrintTime >= inStarTime && p.status == (int)EnumBoardStatus.Printed).ToList();
                    }
                    else
                    {
                        return DataEntites.Board.Where(p => p.lastPrintTime <= inEndTime && p.lastPrintTime >= inStarTime && p.status == (int)EnumBoardStatus.Printed && p.paperFace.PaperFaceID == inPaperFace).ToList();

                    }

                }
                else
                {

                    if (GetPaperFace(inPaperFace).Name.Equals("任意"))
                    {
                        return DataEntites.Board.Where(p => p.lastPrintTime <= inEndTime && p.lastPrintTime >= inStarTime && p.status == (int)EnumBoardStatus.Printed && p.paperType.PaperTypeID == inPaperTypeId).ToList();
                    }
                    else
                    {
                        return DataEntites.Board.Where(p => p.lastPrintTime <= inEndTime && p.lastPrintTime >= inStarTime && p.status == (int)EnumBoardStatus.Printed && p.paperType.PaperTypeID == inPaperTypeId && p.paperFace.PaperFaceID == inPaperFace).ToList();

                    }
                }
            }
            else
            {
                if (GetPaperType(inPaperTypeId).Name.Equals("任意"))
                {
                    if (GetPaperFace(inPaperFace).Name.Equals("任意"))
                    {
                        return DataEntites.Board.Where(p => p.printer.PrinterID == printId && p.lastPrintTime <= inEndTime && p.lastPrintTime >= inStarTime && p.status == (int)EnumBoardStatus.Printed).ToList();
                    }
                    else
                    {
                        return DataEntites.Board.Where(p => p.printer.PrinterID == printId && p.lastPrintTime <= inEndTime && p.lastPrintTime >= inStarTime && p.status == (int)EnumBoardStatus.Printed && p.paperFace.PaperFaceID == inPaperFace).ToList();

                    }

                }
                else
                {

                    if (GetPaperFace(inPaperFace).Name.Equals("任意"))
                    {
                        return DataEntites.Board.Where(p => p.printer.PrinterID == printId && p.lastPrintTime <= inEndTime && p.lastPrintTime >= inStarTime && p.status == (int)EnumBoardStatus.Printed && p.paperType.PaperTypeID == inPaperTypeId).ToList();
                    }
                    else
                    {
                        return DataEntites.Board.Where(p => p.printer.PrinterID == printId && p.lastPrintTime <= inEndTime && p.lastPrintTime >= inStarTime && p.status == (int)EnumBoardStatus.Printed && p.paperType.PaperTypeID == inPaperTypeId && p.paperFace.PaperFaceID == inPaperFace).ToList();

                    }
                }
            }

            
        }
    }
}
